home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / LIB / GLUT / GLUTINT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  27.4 KB  |  768 lines

  1. #ifndef __glutint_h__
  2. #define __glutint_h__
  3.  
  4. /* Copyright (c) Mark J. Kilgard, 1994, 1997, 1998. */
  5.  
  6. /* This program is freely distributable without licensing fees 
  7.    and is provided without guarantee or warrantee expressed or 
  8.    implied. This program is -not- in the public domain. */
  9.  
  10. #if defined(__CYGWIN32__)
  11. #include <sys/time.h>
  12. #endif
  13.  
  14. #if defined(_WIN32)
  15. #include "glutwin32.h"
  16. #else
  17. #ifdef __sgi
  18. #define SUPPORT_FORTRAN
  19. #endif
  20. #include <X11/Xlib.h>
  21. #include <X11/Xutil.h>
  22. #include <GL/glx.h>
  23. #endif
  24.  
  25. #include <GL/glut.h>
  26.  
  27. /* Non-Win32 platforms need APIENTRY defined to nothing
  28.    because all the GLUT routines have the APIENTRY prefix
  29.    to make Win32 happy. */
  30. #ifndef APIENTRY
  31. #define APIENTRY
  32. #endif
  33.  
  34. #ifdef __vms
  35. #if ( __VMS_VER < 70000000 )
  36. struct timeval {
  37.   __int64 val;
  38. };
  39. extern int sys$gettim(struct timeval *);
  40. #else
  41. #include <time.h>
  42. #endif
  43. #else
  44. #include <sys/types.h>
  45. #if !defined(_WIN32)
  46. #include <sys/time.h>
  47. #else
  48. #include <winsock.h>
  49. #endif
  50. #endif
  51. #if defined(__vms) && ( __VMS_VER < 70000000 )
  52.  
  53. /* For VMS6.2 or lower :
  54.    One TICK on VMS is 100 nanoseconds; 0.1 microseconds or
  55.    0.0001 milliseconds. This means that there are 0.01
  56.    ticks/ns, 10 ticks/us, 10,000 ticks/ms and 10,000,000
  57.    ticks/second. */
  58.  
  59. #define TICKS_PER_MILLISECOND 10000
  60. #define TICKS_PER_SECOND      10000000
  61.  
  62. #define GETTIMEOFDAY(_x) (void) sys$gettim (_x);
  63.  
  64. #define ADD_TIME(dest, src1, src2) { \
  65.   (dest).val = (src1).val + (src2).val; \
  66. }
  67.  
  68. #define TIMEDELTA(dest, src1, src2) { \
  69.   (dest).val = (src1).val - (src2).val; \
  70. }
  71.  
  72. #define IS_AFTER(t1, t2) ((t2).val > (t1).val)
  73.  
  74. #define IS_AT_OR_AFTER(t1, t2) ((t2).val >= (t1).val)
  75.  
  76. #else
  77. #if defined(SVR4) && !defined(sun)  /* Sun claims SVR4, but
  78.                                        wants 2 args. */
  79. #define GETTIMEOFDAY(_x) gettimeofday(_x)
  80. #else
  81. #define GETTIMEOFDAY(_x) gettimeofday(_x, NULL)
  82. #endif
  83. #define ADD_TIME(dest, src1, src2) { \
  84.   if(((dest).tv_usec = \
  85.     (src1).tv_usec + (src2).tv_usec) >= 1000000) { \
  86.     (dest).tv_usec -= 1000000; \
  87.     (dest).tv_sec = (src1).tv_sec + (src2).tv_sec + 1; \
  88.   } else { \
  89.     (dest).tv_sec = (src1).tv_sec + (src2).tv_sec; \
  90.     if(((dest).tv_sec >= 1) && (((dest).tv_usec <0))) { \
  91.       (dest).tv_sec --;(dest).tv_usec += 1000000; \
  92.     } \
  93.   } \
  94. }
  95. #define TIMEDELTA(dest, src1, src2) { \
  96.   if(((dest).tv_usec = (src1).tv_usec - (src2).tv_usec) < 0) { \
  97.     (dest).tv_usec += 1000000; \
  98.     (dest).tv_sec = (src1).tv_sec - (src2).tv_sec - 1; \
  99.   } else { \
  100.      (dest).tv_sec = (src1).tv_sec - (src2).tv_sec; \
  101.   } \
  102. }
  103. #define IS_AFTER(t1, t2) \
  104.   (((t2).tv_sec > (t1).tv_sec) || \
  105.   (((t2).tv_sec == (t1).tv_sec) && \
  106.   ((t2).tv_usec > (t1).tv_usec)))
  107. #define IS_AT_OR_AFTER(t1, t2) \
  108.   (((t2).tv_sec > (t1).tv_sec) || \
  109.   (((t2).tv_sec == (t1).tv_sec) && \
  110.   ((t2).tv_usec >= (t1).tv_usec)))
  111. #endif
  112.  
  113. #define IGNORE_IN_GAME_MODE() \
  114.   { if (__glutGameModeWindow) return; }
  115.  
  116. #define GLUT_WIND_IS_RGB(x)         (((x) & GLUT_INDEX) == 0)
  117. #define GLUT_WIND_IS_INDEX(x)       (((x) & GLUT_INDEX) != 0)
  118. #define GLUT_WIND_IS_SINGLE(x)      (((x) & GLUT_DOUBLE) == 0)
  119. #define GLUT_WIND_IS_DOUBLE(x)      (((x) & GLUT_DOUBLE) != 0)
  120. #define GLUT_WIND_HAS_ACCUM(x)      (((x) & GLUT_ACCUM) != 0)
  121. #define GLUT_WIND_HAS_ALPHA(x)      (((x) & GLUT_ALPHA) != 0)
  122. #define GLUT_WIND_HAS_DEPTH(x)      (((x) & GLUT_DEPTH) != 0)
  123. #define GLUT_WIND_HAS_STENCIL(x)    (((x) & GLUT_STENCIL) != 0)
  124. #define GLUT_WIND_IS_MULTISAMPLE(x) (((x) & GLUT_MULTISAMPLE) != 0)
  125. #define GLUT_WIND_IS_STEREO(x)      (((x) & GLUT_STEREO) != 0)
  126. #define GLUT_WIND_IS_LUMINANCE(x)   (((x) & GLUT_LUMINANCE) != 0)
  127. #define GLUT_MAP_WORK               (1 << 0)
  128. #define GLUT_EVENT_MASK_WORK        (1 << 1)
  129. #define GLUT_REDISPLAY_WORK         (1 << 2)
  130. #define GLUT_CONFIGURE_WORK         (1 << 3)
  131. #define GLUT_COLORMAP_WORK          (1 << 4)
  132. #define GLUT_DEVICE_MASK_WORK        (1 << 5)
  133. #define GLUT_FINISH_WORK        (1 << 6)
  134. #define GLUT_DEBUG_WORK            (1 << 7)
  135. #define GLUT_DUMMY_WORK            (1 << 8)
  136. #define GLUT_FULL_SCREEN_WORK       (1 << 9)
  137. #define GLUT_OVERLAY_REDISPLAY_WORK (1 << 10)
  138. #define GLUT_REPAIR_WORK            (1 << 11)
  139. #define GLUT_OVERLAY_REPAIR_WORK    (1 << 12)
  140.  
  141. /* Frame buffer capability macros and types. */
  142. #define RGBA                    0
  143. #define BUFFER_SIZE             1
  144. #define DOUBLEBUFFER            2
  145. #define STEREO                  3
  146. #define AUX_BUFFERS             4
  147. #define RED_SIZE                5  /* Used as mask bit for
  148.                                       "color selected". */
  149. #define GREEN_SIZE              6
  150. #define BLUE_SIZE               7
  151. #define ALPHA_SIZE              8
  152. #define DEPTH_SIZE              9
  153. #define STENCIL_SIZE            10
  154. #define ACCUM_RED_SIZE          11  /* Used as mask bit for
  155.                                        "acc selected". */
  156. #define ACCUM_GREEN_SIZE        12
  157. #define ACCUM_BLUE_SIZE         13
  158. #define ACCUM_ALPHA_SIZE        14
  159. #define LEVEL                   15
  160.  
  161. #define NUM_GLXCAPS             (LEVEL + 1)
  162.  
  163. #define XVISUAL                 (NUM_GLXCAPS + 0)
  164. #define TRANSPARENT             (NUM_GLXCAPS + 1)
  165. #define SAMPLES                 (NUM_GLXCAPS + 2)
  166. #define XSTATICGRAY             (NUM_GLXCAPS + 3)  /* Used as
  167.                                                       mask bit
  168.                                                       for "any
  169.                                                       visual type 
  170.                                                       selected". */
  171. #define XGRAYSCALE              (NUM_GLXCAPS + 4)
  172. #define XSTATICCOLOR            (NUM_GLXCAPS + 5)
  173. #define XPSEUDOCOLOR            (NUM_GLXCAPS + 6)
  174. #define XTRUECOLOR              (NUM_GLXCAPS + 7)
  175. #define XDIRECTCOLOR            (NUM_GLXCAPS + 8)
  176. #define SLOW                    (NUM_GLXCAPS + 9)
  177. #define CONFORMANT              (NUM_GLXCAPS + 10)
  178.  
  179. #define NUM_CAPS                (NUM_GLXCAPS + 11)
  180.  
  181. /* Frame buffer capablities that don't have a corresponding
  182.    FrameBufferMode entry.  These get used as mask bits. */
  183. #define NUM                     (NUM_CAPS + 0)
  184. #define RGBA_MODE               (NUM_CAPS + 1)
  185. #define CI_MODE                 (NUM_CAPS + 2)
  186. #define LUMINANCE_MODE        (NUM_CAPS + 3)
  187.  
  188. #define NONE            0
  189. #define EQ            1
  190. #define NEQ            2
  191. #define LTE            3
  192. #define GTE            4
  193. #define GT            5
  194. #define LT            6
  195. #define MIN            7
  196.  
  197. typedef struct _Criterion {
  198.   int capability;
  199.   int comparison;
  200.   int value;
  201. } Criterion;
  202.  
  203. typedef struct _FrameBufferMode {
  204.   XVisualInfo *vi;
  205. #if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig)
  206.  
  207.   /* fbc is non-NULL when the XVisualInfo* is not OpenGL-capable
  208.      (ie, GLX_USE_GL is false), but the SGIX_fbconfig extension shows
  209.      the visual's fbconfig is OpenGL-capable.  The reason for this is typically
  210.      an RGBA luminance fbconfig such as 16-bit StaticGray that could
  211.      not be advertised as a GLX visual since StaticGray visuals are
  212.      required (by the GLX specification) to be color index.  The
  213.      SGIX_fbconfig allows StaticGray visuals to instead advertised as
  214.      fbconfigs that can provide RGBA luminance support. */
  215.  
  216.   GLXFBConfigSGIX fbc;
  217. #endif
  218.   int valid;
  219.   int cap[NUM_CAPS];
  220. } FrameBufferMode;
  221.  
  222. /* DisplayMode capability macros for game mode. */
  223. #define DM_WIDTH        0  /* "width" */
  224. #define DM_HEIGHT       1  /* "height" */
  225. #define DM_PIXEL_DEPTH  2  /* "bpp" (bits per pixel) */
  226. #define DM_HERTZ        3  /* "hertz" */
  227. #define DM_NUM          4  /* "num" */
  228.  
  229. #define NUM_DM_CAPS     (DM_NUM+1)
  230.  
  231. typedef struct _DisplayMode {
  232. #ifdef _WIN32
  233.   DEVMODE devmode;
  234. #else
  235.   /* XXX The X Window System does not have a standard
  236.      mechanism for display setting changes.  On SGI
  237.      systems, GLUT could use the XSGIvc (SGI X video
  238.      control extension).  Perhaps this can be done in
  239.      a future release of GLUT. */
  240. #endif
  241.   int valid;
  242.   int cap[NUM_DM_CAPS];
  243. } DisplayMode;
  244.  
  245. /* GLUT  function types */
  246. typedef void (*GLUTdisplayCB) (void);
  247. typedef void (*GLUTreshapeCB) (int, int);
  248. typedef void (*GLUTkeyboardCB) (unsigned char, int, int);
  249. typedef void (*GLUTmouseCB) (int, int, int, int);
  250. typedef void (*GLUTmotionCB) (int, int);
  251. typedef void (*GLUTpassiveCB) (int, int);
  252. typedef void (*GLUTentryCB) (int);
  253. typedef void (*GLUTvisibilityCB) (int);
  254. typedef void (*GLUTwindowStatusCB) (int);
  255. typedef void (*GLUTidleCB) (void);
  256. typedef void (*GLUTtimerCB) (int);
  257. typedef void (*GLUTmenuStateCB) (int);  /* DEPRICATED. */
  258. typedef void (*GLUTmenuStatusCB) (int, int, int);
  259. typedef void (*GLUTselectCB) (int);
  260. typedef void (*GLUTspecialCB) (int, int, int);
  261. typedef void (*GLUTspaceMotionCB) (int, int, int);
  262. typedef void (*GLUTspaceRotateCB) (int, int, int);
  263. typedef void (*GLUTspaceButtonCB) (int, int);
  264. typedef void (*GLUTdialsCB) (int, int);
  265. typedef void (*GLUTbuttonBoxCB) (int, int);
  266. typedef void (*GLUTtabletMotionCB) (int, int);
  267. typedef void (*GLUTtabletButtonCB) (int, int, int, int);
  268. typedef void (*GLUTjoystickCB) (unsigned int buttonMask, int x, int y, int z);
  269. #ifdef SUPPORT_FORTRAN
  270. typedef void (*GLUTdisplayFCB) (void);
  271. typedef void (*GLUTreshapeFCB) (int *, int *);
  272. /* NOTE the pressed key is int, not unsigned char for Fortran! */
  273. typedef void (*GLUTkeyboardFCB) (int *, int *, int *);
  274. typedef void (*GLUTmouseFCB) (int *, int *, int *, int *);
  275. typedef void (*GLUTmotionFCB) (int *, int *);
  276. typedef void (*GLUTpassiveFCB) (int *, int *);
  277. typedef void (*GLUTentryFCB) (int *);
  278. typedef void (*GLUTvisibilityFCB) (int *);
  279. typedef void (*GLUTwindowStatusFCB) (int *);
  280. typedef void (*GLUTidleFCB) (void);
  281. typedef void (*GLUTtimerFCB) (int *);
  282. typedef void (*GLUTmenuStateFCB) (int *);  /* DEPRICATED. */
  283. typedef void (*GLUTmenuStatusFCB) (int *, int *, int *);
  284. typedef void (*GLUTselectFCB) (int *);
  285. typedef void (*GLUTspecialFCB) (int *, int *, int *);
  286. typedef void (*GLUTspaceMotionFCB) (int *, int *, int *);
  287. typedef void (*GLUTspaceRotateFCB) (int *, int *, int *);
  288. typedef void (*GLUTspaceButtonFCB) (int *, int *);
  289. typedef void (*GLUTdialsFCB) (int *, int *);
  290. typedef void (*GLUTbuttonBoxFCB) (int *, int *);
  291. typedef void (*GLUTtabletMotionFCB) (int *, int *);
  292. typedef void (*GLUTtabletButtonFCB) (int *, int *, int *, int *);
  293. typedef void (*GLUTjoystickFCB) (unsigned int *buttonMask, int *x, int *y, int *z);
  294. #endif
  295.  
  296. typedef struct _GLUTcolorcell GLUTcolorcell;
  297. struct _GLUTcolorcell {
  298.   /* GLUT_RED, GLUT_GREEN, GLUT_BLUE */
  299.   GLfloat component[3];
  300. };
  301.  
  302. typedef struct _GLUTcolormap GLUTcolormap;
  303. struct _GLUTcolormap {
  304.   Visual *visual;       /* visual of the colormap */
  305.   Colormap cmap;        /* X colormap ID */
  306.   int refcnt;           /* number of windows using colormap */
  307.   int size;             /* number of cells in colormap */
  308.   int transparent;      /* transparent pixel, or -1 if opaque */
  309.   GLUTcolorcell *cells; /* array of cells */
  310.   GLUTcolormap *next;   /* next colormap in list */
  311. };
  312.  
  313. typedef struct _GLUTwindow GLUTwindow;
  314. typedef struct _GLUToverlay GLUToverlay;
  315. struct _GLUTwindow {
  316.   int num;              /* Small integer window id (0-based). */
  317.  
  318.   /* Window system related state. */
  319. #if defined(_WIN32)
  320.   int pf;               /* Pixel format. */
  321.   HDC hdc;              /* Window's Win32 device context. */
  322. #endif
  323.   Window win;           /* X window for GLUT window */
  324.   GLXContext ctx;       /* OpenGL context GLUT glut window */
  325.   XVisualInfo *vis;     /* visual for window */
  326.   Bool visAlloced;      /* if vis needs deallocate on destroy */
  327.   Colormap cmap;        /* RGB colormap for window; None if CI */
  328.   GLUTcolormap *colormap;  /* colormap; NULL if RGBA */
  329.   GLUToverlay *overlay; /* overlay; NULL if no overlay */
  330. #if defined(_WIN32)
  331.   HDC renderDc;         /* Win32's device context for rendering. */
  332. #endif
  333.   Window renderWin;     /* X window for rendering (might be
  334.                            overlay) */
  335.   GLXContext renderCtx; /* OpenGL context for rendering (might
  336.                            be overlay) */
  337.   /* GLUT settable or visible window state. */
  338.   int width;            /* window width in pixels */
  339.   int height;           /* window height in pixels */
  340.   int cursor;           /* cursor name */
  341.   int visState;         /* visibility state (-1 is unknown) */
  342.   int shownState;       /* if window mapped */
  343.   int entryState;       /* entry state (-1 is unknown) */
  344. #define GLUT_MAX_MENUS              3
  345.  
  346.   int menu[GLUT_MAX_MENUS];  /* attatched menu nums */
  347.   /* Window relationship state. */
  348.   GLUTwindow *parent;   /* parent window */
  349.   GLUTwindow *children; /* list of children */
  350.   GLUTwindow *siblings; /* list of siblings */
  351.   /* Misc. non-API visible (hidden) state. */
  352.   Bool treatAsSingle;   /* treat this window as single-buffered
  353.                            (it might be "fake" though) */
  354.   Bool forceReshape;    /* force reshape before display */
  355. #if !defined(_WIN32)
  356.   Bool isDirect;        /* if direct context (X11 only) */
  357. #endif
  358.   Bool usedSwapBuffers; /* if swap buffers used last display */
  359.   long eventMask;       /* mask of X events selected for */
  360.   int buttonUses;       /* number of button uses, ref cnt */
  361.   int tabletPos[2];     /* tablet position (-1 is invalid) */
  362.   /* Work list related state. */
  363.   unsigned int workMask;  /* mask of window work to be done */
  364.   GLUTwindow *prevWorkWin;  /* link list of windows to work on */
  365.   Bool desiredMapState; /* how to mapped window if on map work
  366.                            list */
  367.   Bool ignoreKeyRepeat;  /* if window ignores autorepeat */
  368.   int desiredConfMask;  /* mask of desired window configuration
  369.                          */
  370.   int desiredX;         /* desired X location */
  371.   int desiredY;         /* desired Y location */
  372.   int desiredWidth;     /* desired window width */
  373.   int desiredHeight;    /* desired window height */
  374.   int desiredStack;     /* desired window stack */
  375.   /* Per-window callbacks. */
  376.   GLUTdisplayCB display;  /* redraw */
  377.   GLUTreshapeCB reshape;  /* resize (width,height) */
  378.   GLUTmouseCB mouse;    /* mouse (button,state,x,y) */
  379.   GLUTmotionCB motion;  /* motion (x,y) */
  380.   GLUTpassiveCB passive;  /* passive motion (x,y) */
  381.   GLUTentryCB entry;    /* window entry/exit (state) */
  382.   GLUTkeyboardCB keyboard;  /* keyboard (ASCII,x,y) */
  383.   GLUTkeyboardCB keyboardUp;  /* keyboard up (ASCII,x,y) */
  384.   GLUTwindowStatusCB windowStatus;  /* window status */
  385.   GLUTvisibilityCB visibility;  /* visibility */
  386.   GLUTspecialCB special;  /* special key */
  387.   GLUTspecialCB specialUp;  /* special up key */
  388.   GLUTbuttonBoxCB buttonBox;  /* button box */
  389.   GLUTdialsCB dials;    /* dials */
  390.   GLUTspaceMotionCB spaceMotion;  /* Spaceball motion */
  391.   GLUTspaceRotateCB spaceRotate;  /* Spaceball rotate */
  392.   GLUTspaceButtonCB spaceButton;  /* Spaceball button */
  393.   GLUTtabletMotionCB tabletMotion;  /* tablet motion */
  394.   GLUTtabletButtonCB tabletButton;  /* tablet button */
  395. #ifdef _WIN32
  396.   GLUTjoystickCB joystick;  /* joystick */
  397.   int joyPollInterval; /* joystick polling interval */
  398. #endif
  399. #ifdef SUPPORT_FORTRAN
  400.   /* Special Fortran display  unneeded since no
  401.      parameters! */
  402.   GLUTreshapeFCB freshape;  /* Fortran reshape  */
  403.   GLUTmouseFCB fmouse;  /* Fortran mouse  */
  404.   GLUTmotionFCB fmotion;  /* Fortran motion  */
  405.   GLUTpassiveFCB fpassive;  /* Fortran passive  */
  406.   GLUTentryFCB fentry;  /* Fortran entry  */
  407.   GLUTkeyboardFCB fkeyboard;  /* Fortran keyboard  */
  408.   GLUTkeyboardFCB fkeyboardUp;  /* Fortran keyboard up */
  409.   GLUTwindowStatusFCB fwindowStatus;  /* Fortran visibility
  410.                                           */
  411.   GLUTvisibilityFCB fvisibility;  /* Fortran visibility
  412.                                       */
  413.   GLUTspecialFCB fspecial;  /* special key */
  414.   GLUTspecialFCB fspecialUp;  /* special key up */
  415.   GLUTbuttonBoxFCB fbuttonBox;  /* button box */
  416.   GLUTdialsFCB fdials;  /* dials */
  417.   GLUTspaceMotionFCB fspaceMotion;  /* Spaceball motion
  418.                                         */
  419.   GLUTspaceRotateFCB fspaceRotate;  /* Spaceball rotate
  420.                                         */
  421.   GLUTspaceButtonFCB fspaceButton;  /* Spaceball button
  422.                                         */
  423.   GLUTtabletMotionFCB ftabletMotion;  /* tablet motion
  424.                                        */
  425.   GLUTtabletButtonFCB ftabletButton;  /* tablet button
  426.                                        */
  427. #ifdef _WIN32
  428.   GLUTjoystickFCB fjoystick;  /* joystick */
  429. #endif
  430. #endif
  431. };
  432.  
  433. struct _GLUToverlay {
  434. #if defined(_WIN32)
  435.   int pf;
  436.   HDC hdc;
  437. #endif
  438.   Window win;
  439.   GLXContext ctx;
  440.   XVisualInfo *vis;     /* visual for window */
  441.   Bool visAlloced;      /* if vis needs deallocate on destroy */
  442.   Colormap cmap;        /* RGB colormap for window; None if CI */
  443.   GLUTcolormap *colormap;  /* colormap; NULL if RGBA */
  444.   int shownState;       /* if overlay window mapped */
  445.   Bool treatAsSingle;   /* treat as single-buffered */
  446. #if !defined(_WIN32)
  447.   Bool isDirect;        /* if direct context */
  448. #endif
  449.   int transparentPixel; /* transparent pixel value */
  450.   GLUTdisplayCB display;  /* redraw  */
  451.   /* Special Fortran display  unneeded since no
  452.      parameters! */
  453. };
  454.  
  455. typedef struct _GLUTstale GLUTstale;
  456. struct _GLUTstale {
  457.   GLUTwindow *window;
  458.   Window win;
  459.   GLUTstale *next;
  460. };
  461.  
  462. extern GLUTstale *__glutStaleWindowList;
  463.  
  464. #define GLUT_OVERLAY_EVENT_FILTER_MASK \
  465.   (ExposureMask | \
  466.   StructureNotifyMask | \
  467.   EnterWindowMask | \
  468.   LeaveWindowMask)
  469. #define GLUT_DONT_PROPAGATE_FILTER_MASK \
  470.   (ButtonReleaseMask | \
  471.   ButtonPressMask | \
  472.   KeyPressMask | \
  473.   KeyReleaseMask | \
  474.   PointerMotionMask | \
  475.   Button1MotionMask | \
  476.   Button2MotionMask | \
  477.   Button3MotionMask)
  478. #define GLUT_HACK_STOP_PROPAGATE_MASK \
  479.   (KeyPressMask | \
  480.   KeyReleaseMask)
  481.  
  482. typedef struct _GLUTmenu GLUTmenu;
  483. typedef struct _GLUTmenuItem GLUTmenuItem;
  484. struct _GLUTmenu {
  485.   int id;               /* small integer menu id (0-based) */
  486.   Window win;           /* X window for the menu */
  487.   GLUTselectCB select;  /*  function of menu */
  488.   GLUTmenuItem *list;   /* list of menu entries */
  489.   int num;              /* number of entries */
  490. #if !defined(_WIN32)
  491.   Bool managed;         /* are the InputOnly windows size
  492.                            validated? */
  493.   Bool searched;    /* help detect menu loops */
  494.   int pixheight;        /* height of menu in pixels */
  495.   int pixwidth;         /* width of menu in pixels */
  496. #endif
  497.   int submenus;         /* number of submenu entries */
  498.   GLUTmenuItem *highlighted;  /* pointer to highlighted menu
  499.                                  entry, NULL not highlighted */
  500.   GLUTmenu *cascade;    /* currently cascading this menu  */
  501.   GLUTmenuItem *anchor; /* currently anchored to this entry */
  502.   int x;                /* current x origin relative to the
  503.                            root window */
  504.   int y;                /* current y origin relative to the
  505.                            root window */
  506. #ifdef SUPPORT_FORTRAN
  507.   GLUTselectFCB fselect;  /*  function of menu */
  508. #endif
  509. };
  510.  
  511. struct _GLUTmenuItem {
  512.   Window win;           /* InputOnly X window for entry */
  513.   GLUTmenu *menu;       /* menu entry belongs to */
  514.   Bool isTrigger;       /* is a submenu trigger? */
  515.   int value;            /* value to return for selecting this
  516.                            entry; doubles as submenu id
  517.                            (0-base) if submenu trigger */
  518. #if defined(_WIN32)
  519.   UINT unique;          /* unique menu item id (Win32 only) */
  520. #endif
  521.   char *label;          /* __glutStrdup'ed label string */
  522.   int len;              /* length of label string */
  523.   int pixwidth;         /* width of X window in pixels */
  524.   GLUTmenuItem *next;   /* next menu entry on list for menu */
  525. };
  526.  
  527. typedef struct _GLUTtimer GLUTtimer;
  528. struct _GLUTtimer {
  529.   GLUTtimer *next;      /* list of timers */
  530.   struct timeval timeout;  /* time to be called */
  531.   GLUTtimerCB func;     /* timer  (value) */
  532.   int value;            /*  return value */
  533. #ifdef SUPPORT_FORTRAN
  534.   GLUTtimerFCB ffunc;   /* Fortran timer  */
  535. #endif
  536. };
  537.  
  538. typedef struct _GLUTeventParser GLUTeventParser;
  539. struct _GLUTeventParser {
  540.   int (*func) (XEvent *);
  541.   GLUTeventParser *next;
  542. };
  543.  
  544. /* Declarations to implement glutFullScreen support with
  545.    mwm/4Dwm. */
  546.  
  547. /* The following X property format is defined in Motif 1.1's
  548.    Xm/MwmUtils.h, but GLUT should not depend on that header
  549.    file. Note: Motif 1.2 expanded this structure with
  550.    uninteresting fields (to GLUT) so just stick with the
  551.    smaller Motif 1.1 structure. */
  552. typedef struct {
  553. #define MWM_HINTS_DECORATIONS   2
  554.   long flags;
  555.   long functions;
  556.   long decorations;
  557.   long input_mode;
  558. } MotifWmHints;
  559.  
  560. /* Make current and buffer swap macros. */
  561. #ifdef _WIN32
  562. #define MAKE_CURRENT_LAYER(window)                                    \
  563.   {                                                                   \
  564.     HGLRC currentContext = wglGetCurrentContext();                    \
  565.     HDC currentDc = wglGetCurrentDC();                                \
  566.                                                                       \
  567.     if (currentContext != window->renderCtx                           \
  568.       || currentDc != window->renderDc) {                             \
  569.       wglMakeCurrent(window->renderDc, window->renderCtx);            \
  570.     }                                                                 \
  571.   }
  572. #define MAKE_CURRENT_WINDOW(window)                                   \
  573.   {                                                                   \
  574.     HGLRC currentContext = wglGetCurrentContext();                    \
  575.     HDC currentDc = wglGetCurrentDC();                                \
  576.                                                                       \
  577.     if (currentContext != window->ctx || currentDc != window->hdc) {  \
  578.       wglMakeCurrent(window->hdc, window->ctx);                       \
  579.     }                                                                 \
  580.   }
  581. #define MAKE_CURRENT_OVERLAY(overlay) \
  582.   wglMakeCurrent(overlay->hdc, overlay->ctx)
  583. #define UNMAKE_CURRENT() \
  584.   wglMakeCurrent(NULL, NULL)
  585. #define SWAP_BUFFERS_WINDOW(window) \
  586.   SwapBuffers(window->hdc)
  587. #define SWAP_BUFFERS_LAYER(window) \
  588.   SwapBuffers(window->renderDc)
  589. #else
  590. #define MAKE_CURRENT_LAYER(window) \
  591.   glXMakeCurrent(__glutDisplay, window->renderWin, window->renderCtx)
  592. #define MAKE_CURRENT_WINDOW(window) \
  593.   glXMakeCurrent(__glutDisplay, window->win, window->ctx)
  594. #define MAKE_CURRENT_OVERLAY(overlay) \
  595.   glXMakeCurrent(__glutDisplay, overlay->win, overlay->ctx)
  596. #define UNMAKE_CURRENT() \
  597.   glXMakeCurrent(__glutDisplay, None, NULL)
  598. #define SWAP_BUFFERS_WINDOW(window) \
  599.   glXSwapBuffers(__glutDisplay, window->win)
  600. #define SWAP_BUFFERS_LAYER(window) \
  601.   glXSwapBuffers(__glutDisplay, window->renderWin)
  602. #endif
  603.  
  604. /* private variables from glut_event.c */
  605. extern GLUTwindow *__glutWindowWorkList;
  606. extern int __glutWindowDamaged;
  607. #ifdef SUPPORT_FORTRAN
  608. extern GLUTtimer *__glutTimerList;
  609. extern GLUTtimer *__glutNewTimer;
  610. #endif
  611. extern GLUTmenu *__glutMappedMenu;
  612.  
  613. extern void (*__glutUpdateInputDeviceMaskFunc) (GLUTwindow *);
  614. #if !defined(_WIN32)
  615. extern void (*__glutMenuItemEnterOrLeave)(GLUTmenuItem * item,
  616.   int num, int type);
  617. extern void (*__glutFinishMenu)(Window win, int x, int y);
  618. extern void (*__glutPaintMenu)(GLUTmenu * menu);
  619. extern void (*__glutStartMenu)(GLUTmenu * menu,
  620.   GLUTwindow * window, int x, int y, int x_win, int y_win);
  621. extern GLUTmenu * (*__glutGetMenuByNum)(int menunum);
  622. extern GLUTmenuItem * (*__glutGetMenuItem)(GLUTmenu * menu,
  623.   Window win, int *which);
  624. extern GLUTmenu * (*__glutGetMenu)(Window win);
  625. #endif
  626.  
  627. /* private variables from glut_init.c */
  628. extern Atom __glutWMDeleteWindow;
  629. extern Display *__glutDisplay;
  630. extern unsigned int __glutDisplayMode;
  631. extern char *__glutDisplayString;
  632. extern XVisualInfo *(*__glutDetermineVisualFromString) (char *string, Bool * treatAsSingle,
  633.   Criterion * requiredCriteria, int nRequired, int requiredMask, void **fbc);
  634. extern GLboolean __glutDebug;
  635. extern GLboolean __glutForceDirect;
  636. extern GLboolean __glutIconic;
  637. extern GLboolean __glutTryDirect;
  638. extern Window __glutRoot;
  639. extern XSizeHints __glutSizeHints;
  640. extern char **__glutArgv;
  641. extern char *__glutProgramName;
  642. extern int __glutArgc;
  643. extern int __glutConnectionFD;
  644. extern int __glutInitHeight;
  645. extern int __glutInitWidth;
  646. extern int __glutInitX;
  647. extern int __glutInitY;
  648. extern int __glutScreen;
  649. extern int __glutScreenHeight;
  650. extern int __glutScreenWidth;
  651. extern Atom __glutMotifHints;
  652. extern unsigned int __glutModifierMask;
  653.  
  654. /* private variables from glut_menu.c */
  655. extern GLUTmenuItem *__glutItemSelected;
  656. extern GLUTmenu **__glutMenuList;
  657. extern void (*__glutMenuStatusFunc) (int, int, int);
  658. extern void __glutMenuModificationError(void);
  659. extern void __glutSetMenuItem(GLUTmenuItem * item,
  660.   const char *label, int value, Bool isTrigger);
  661.  
  662. /* private variables from glut_win.c */
  663. extern GLUTwindow **__glutWindowList;
  664. extern GLUTwindow *__glutCurrentWindow;
  665. extern GLUTwindow *__glutMenuWindow;
  666. extern GLUTmenu *__glutCurrentMenu;
  667. extern int __glutWindowListSize;
  668. extern void (*__glutFreeOverlayFunc) (GLUToverlay *);
  669. extern XVisualInfo *__glutDetermineWindowVisual(Bool * treatAsSingle,
  670.   Bool * visAlloced, void **fbc);
  671.  
  672. /* private variables from glut_mesa.c */
  673. extern int __glutMesaSwapHackSupport;
  674.  
  675. /* private variables from glut_gamemode.c */
  676. extern GLUTwindow *__glutGameModeWindow;
  677.  
  678. /* private routines from glut_cindex.c */
  679. extern GLUTcolormap * __glutAssociateNewColormap(XVisualInfo * vis);
  680. extern void __glutFreeColormap(GLUTcolormap *);
  681.  
  682. /* private routines from glut_cmap.c */
  683. extern void __glutSetupColormap(
  684.   XVisualInfo * vi,
  685.   GLUTcolormap ** colormap,
  686.   Colormap * cmap);
  687. #if !defined(_WIN32)
  688. extern void __glutEstablishColormapsProperty(
  689.   GLUTwindow * window);
  690. extern GLUTwindow *__glutToplevelOf(GLUTwindow * window);
  691. #endif
  692.  
  693. /* private routines from glut_cursor.c */
  694. extern void __glutSetCursor(GLUTwindow *window);
  695.  
  696. /* private routines from glut_event.c */
  697. extern void __glutPutOnWorkList(GLUTwindow * window,
  698.   int work_mask);
  699. extern void __glutRegisterEventParser(GLUTeventParser * parser);
  700. extern void __glutPostRedisplay(GLUTwindow * window, int layerMask);
  701.  
  702. /* private routines from glut_init.c */
  703. #if !defined(_WIN32)
  704. extern void __glutOpenXConnection(char *display);
  705. #else
  706. extern void __glutOpenWin32Connection(char *display);
  707. #endif
  708. extern void __glutInitTime(struct timeval *beginning);
  709.  
  710. /* private routines for glut_menu.c (or win32_menu.c) */
  711. #if defined(_WIN32)
  712. extern GLUTmenu *__glutGetMenu(Window win);
  713. extern GLUTmenu *__glutGetMenuByNum(int menunum);
  714. extern GLUTmenuItem *__glutGetMenuItem(GLUTmenu * menu,
  715.   Window win, int *which);
  716. extern void __glutStartMenu(GLUTmenu * menu,
  717.   GLUTwindow * window, int x, int y, int x_win, int y_win);
  718. extern void __glutFinishMenu(Window win, int x, int y);
  719. #endif
  720. extern void __glutSetMenu(GLUTmenu * menu);
  721.  
  722. /* private routines from glut_util.c */
  723. extern char * __glutStrdup(const char *string);
  724. extern void __glutWarning(char *format,...);
  725. extern void __glutFatalError(char *format,...);
  726. extern void __glutFatalUsage(char *format,...);
  727.  
  728. /* private routines from glut_win.c */
  729. extern GLUTwindow *__glutGetWindow(Window win);
  730. extern void __glutChangeWindowEventMask(long mask, Bool add);
  731. extern XVisualInfo *__glutDetermineVisual(
  732.   unsigned int mode,
  733.   Bool * fakeSingle,
  734.   XVisualInfo * (getVisualInfo) (unsigned int));
  735. extern XVisualInfo *__glutGetVisualInfo(unsigned int mode);
  736. extern void __glutSetWindow(GLUTwindow * window);
  737. extern void __glutReshapeFunc(GLUTreshapeCB reshapeFunc,
  738.   int callingConvention);
  739. extern void  __glutDefaultReshape(int, int);
  740. extern GLUTwindow *__glutCreateWindow(
  741.   GLUTwindow * parent,
  742.   int x, int y, int width, int height, int gamemode);
  743. extern void __glutDestroyWindow(
  744.   GLUTwindow * window,
  745.   GLUTwindow * initialWindow);
  746.  
  747. #if !defined(_WIN32)
  748. /* private routines from glut_glxext.c */
  749. extern int __glutIsSupportedByGLX(char *);
  750. #endif
  751.  
  752. /* private routines from glut_input.c */
  753. extern void  __glutUpdateInputDeviceMask(GLUTwindow * window);
  754.  
  755. /* private routines from glut_mesa.c */
  756. extern void __glutDetermineMesaSwapHackSupport(void);
  757.  
  758. /* private routines from glut_gameglut.c */
  759. extern void __glutCloseDownGameMode(void);
  760.  
  761. #if defined(_WIN32)
  762. /* private routines from win32_*.c */
  763. extern LONG WINAPI __glutWindowProc(HWND win, UINT msg, WPARAM w, LPARAM l);
  764. extern HDC XHDC;
  765. #endif
  766.  
  767. #endif /* __glutint_h__ */
  768.